<?php

namespace common\models\sys;

use Yii;

/**
 * This is the model class for table "sys_operation".
 *
 * @property string $id
 * @property integer $userid
 * @property string $operation
 * @property integer $createtime
 * @property string $other
 */
class SysOperation extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'sys_operation';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['userid', 'operation', 'createtime', 'other'], 'required'],
            [['userid', 'createtime'], 'integer'],
            [['operation', 'other'], 'string', 'max' => 255],
            [['upimg'], 'string', 'max' => 500],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'userid' => 'Userid',
            'operation' => 'Operation',
            'createtime' => 'Createtime',
            'other' => 'Other',
        ];
    }


    /**
     * @param $operation  操作记录
     * @param $other    其他
     * 插入操作日志
     */
    public static function opLog($operation,$other='',$upimg='')
    {
        $data = [
            'userid' => Yii::$app->user->id,
            'operation' => $operation,
            'other' => $other,
            'upimg' => $upimg,
            'createtime' => time()
        ];
        Yii::$app->db->createCommand()->insert(self::tableName(),$data)->execute();
    }



}

